package org.community.picture.controller;


import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.community.picture.repository.dao.CustomFile;
import org.community.picture.repository.flag.PictureEnum;
import org.community.picture.service.download.DownloadService;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Data
@Slf4j
public class DownloadController {

    @Resource
    private DownloadService downloadService;


    //控制层返回图片字节流
    @GetMapping(
            value = "/portrait/{userId}"
    )
    public ResponseEntity<byte[]> getUserPortrait(@PathVariable("userId") Integer userId){
        log.info("getUserPortrait开始执行");
        CustomFile downloadRequest = new CustomFile();
        downloadRequest.setUserId(userId);
        downloadRequest.setType(PictureEnum.portrait);

        return downloadService.getResponseBodyPortrait(downloadRequest);
    }
}
